home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-04-08 | 23.7 KB | 573 lines | [TEXT/CCL2] |
- #|
- draw-item-class.lisp
-
- Defines the DRAW-ITEM class and subclasses used in the Mini-Application
- sample program.
-
- For further info, see files "About Mini-App" and "Instructions".
-
-
- Copyright 1990, 1991 by Ruben Kleiman for Apple Computer, Inc.
-
- Change History.
- 03-12-92 slm Facilitated save-application by delaying getting the
- handle to tool icons until they are first drawn.
- Removed open-resource-file from create-draw-item,
- and added a filename parameter to get-resource-handle
- in view-draw-contents for icon-draw-items.
- Methods set-view-position and set-view-size for draw-items
- were removed because they have no effect beyond
- call-next-method!
- 03-11-92 slm Changed all occurrences of defvar to defparameter (1)
- so that after the Mini-Application is modified, the
- changed files can be re-evaluated immediately.
- Renamed "color-icon" to "icon-draw-item" as it does not
- have to be color. Replaced its unused "size" slot
- with an initial value for its view-size.
- 03-09-92 slm Updated file header comments.
- 03-08-92 slm "mini-application;resources" -> "ccl:mini-app;resources"
- in create-draw-item.
- 01-19-92 slm Added *color-available* test, & #_PlotIcon for B&W systems.
- class color-icon: increased :size from #@(16 16) to #@(32 32)
- 01-17-92 slm _PtInRect -> #_PtInRect
- _framerect -> #_FrameRect (2x)
- _inverrect -> #_InvertRect (2x) ("t" added)
- _RectRgn -> #_RectRgn (2x)
- _xorrgn# -> #_XOrRgn
- _inverRgn -> #_InvertRgn ("t" added)
- _frameoval -> #_FrameOval
- _loadresource -> #_LoadResource
- _plotcicon -> #_PlotCIcon
- In addition, most keywords such as :word were removed.
- :window -> :windowRecord (2x)
- (bring-item-to-front (view-container) item) ->
- (bring-item-to-front (view-container item) item)
-
- |#
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; DRAW-ITEM
- ;;;
- ;;; This section defines the behavior of the objects which will be
- ;;; draggable from our palette window onto our draw windows.
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; DRAW-ITEM Class
- ;;;
- ;;; This is the main class of graphical objects which can be either
- ;;; in one of our palettes (instances of the PALETTE class) or
- ;;; in our windows (instances of the DRAW-DIALOG class)
- ;;;
- (defclass draw-item (dialog-item)
- ((rectangle :initarg :rectangle :initform nil) ; Rectangle for dragging, resizing, drawing, etc.
- (tool :initarg :tool :initform nil) ; Is this a item used as a tool?
- (selected :initform nil) ; Is this item selected?
- (name :initarg :name :initform "")) ; The name of this item, if any.
- (:documentation "The user interface objects"))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; RESOURCE class
- ;;;
- ;;; May be used to compose an item which gets some of
- ;;; its data from a resource.
- ;;;
- (defclass resource ()
- ((resource-handle :initarg :resource-handle :initform nil) ; Resource Handle
- (resource-id :initarg :resource-id :initform nil) ; Resource ID
- (resource-type :initarg :resource-type :initform nil)) ; Resource type
- )
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; *slop-in-pixels*
- ;;;
- ;;; The amount of slop allowed when resizing a DRAW-ITEM
- ;;;
- (defparameter *slop-in-pixels* 4)
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; author-mode-click-handler
- ;;;
- ;;; Gets called whenever there is a click in a DRAW-DIALOG window,
- ;;; the click was over a draw item in the window, and
- ;;; the window is in author mode (i.e., not in browse mode)
- ;;;
- (defmethod author-mode-click-handler ((item draw-item) where)
- (if (double-click-p)
- (author-mode-double-click-handler item where)
- (author-mode-single-click-handler item where)))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; author-mode-double-click-handler
- ;;;
- ;;; Gets called when there is a double click on the DRAW-DIALOG window,
- ;;; the click was over a draw item in the window, and
- ;;; the window is in author mode
- ;;;
- (defmethod author-mode-double-click-handler ((item draw-item) where)
- (declare (ignore where))
- ;; Show object information (same as selecting Object Info... menu item)
- (show-object-info item)
- )
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; author-mode-single-click-handler
- ;;;
- ;;; Gets called when there is a double click on the DRAW-DIALOG window,
- ;;; the click was over a draw item in the window, and
- ;;; the window is in author mode
- ;;;
- (defmethod author-mode-single-click-handler ((item draw-item) mouse-loc)
- (let ((window (view-container item)))
- ;; Check for resize or drag only if mouse moves before it is released:
- (if (loop
- (cond ((not (mouse-down-p))
- (return nil))
- ((neq (view-mouse-position window) mouse-loc)
- (return t))))
- ;; Decide whether we are going to drag or resize it:
- (if (resize? item mouse-loc)
- (resize item mouse-loc)
- (maybe-drag item mouse-loc)))
- ;; Deselect others and select it:
- (deselect-items window)
- (select-item item)))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; select-item
- ;;;
- ;;; Called to make item selected.
- ;;;
- (defmethod select-item ((item draw-item))
- (setf (slot-value item 'selected) t) ; Set selected flag
- (set-menu-title *selected-object-menu-indicator* ; Advice menubar
- (concatenate 'string "Selected: " (slot-value item 'name)))
- (show-handles item) ; Show object handles
- (pushnew item ; Add item to window's selections list
- (slot-value (view-container item) 'selections)))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; show-handles
- ;;;
- ;;; Show selection handles for item. Called whenever
- ;;; the handles must be drawn. This is left as
- ;;; an artistic exercise to the reader!
- ;;;
- (defmethod show-handles ((item draw-item))
- )
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; view-draw-contents
- ;;;
- ;;; The draw-item will draw its handles if it is selected
- ;;;
- (defmethod view-draw-contents ((item draw-item))
- (call-next-method)
- (if (slot-value item 'selected)
- (show-handles item)))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; find-draw-dialog-in-point
- ;;;
- ;;; This will find the frontmost draw-dialog window where
- ;;; the POINT lies.
- ;;;
- (defun find-draw-dialog-in-point (point)
- (dolist (window (windows :class 'draw-dialog))
- (and (#_PtInRect :long (subtract-points point (view-position window))
- :ptr (rref (wptr window) :windowRecord.portRect)
- :boolean)
- (return window))))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; move-item-to-window
- ;;;
- ;;; Called when we want to move draw-item ITEM from window SOURCE to
- ;;; window DESTINATION. If SOURCE is a PALETTE, we want to clone the
- ;;; item from the palette; if SOURCE is a window, we are going
- ;;; to move the actual item. WHERE is the SOURCE-relative coordinate where we want
- ;;; the item to be positioned in the DESTINATION window.
- ;;;
- (defun move-item-to-window (item where source destination)
- (let* ((global-position (add-points where (view-position source)))
- (local-position
- (subtract-points global-position (view-position destination))))
- (cond ((and (neq (type-of source) 'PALETTE)
- (neq (type-of destination) 'PALETTE))
- ;; If neither SOURCE not DESTINATION is a palette, then it is a normal object move
- (remove-subviews source item)
- (add-subviews destination item)
- (set-view-position item local-position)
- (window-select destination))
- (t
- ;; If SOURCE is a palette, then we are cloning the palette object,
- ;; leaving the original object in the palette (as some might expect)
- (let ((clone (clone-draw-item item)))
- (set-view-position clone local-position)
- (add-items destination clone))))
- (window-select destination)))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; clone-draw-item
- ;;;
- ;;; This clones a draw item. Palette items are cloned from the
- ;;; palettes when they are moved to another window. The original
- ;;; palette item appears undisturbed in the palette even after the move.
- ;;;
- (defmethod clone-draw-item ((item draw-item))
- (let ((clone (make-instance (type-of item)
- :view-position (view-position item)
- :view-size (view-size item)
- :name (concatenate 'string
- (slot-value item 'name)
- (string (gentemp)))))
- (resource-handle (and (slot-exists-p item 'resource-handle)
- (slot-value item 'resource-handle))))
- ;; Set resource handle, if any (note assumption that resources are shared!):
- (if resource-handle
- (setf (slot-value clone 'resource-handle) resource-handle))
- ;; Set a rectangle:
- (setf (slot-value clone 'rectangle)
- (make-record :rect :topleft 0 :bottomright 0))
- clone)) ; Return clone
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; view-center
- ;;;
- ;;; This returns the ideal center of a draw-item.
- ;;;
- (defmethod view-center ((item draw-item))
- (truncate (+ (view-position item)
- (add-points (view-position item)
- (view-size item)))
- 2))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; maybe-drag
- ;;;
- ;;; Called when the item may have to be dragged.
- ;;; Tools are not draggable.
- ;;;
- (defmethod maybe-drag ((item draw-item) current-mouse-loc)
- (cond ((slot-value item 'tool)
- (ed-beep)
- (window-select *top-listener*)
- (format t "~%Can't drag ~A out of palette because it's a tool!"
- (slot-value item 'name)))
- (t (drag item current-mouse-loc))))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; drag
- ;;;
- ;;; Called when item must be dragged by user
- ;;;
- (defmethod drag ((item draw-item) current-mouse-loc)
- (let ((start-position (view-position item)) ; where are we starting the drag from?
- (end-position nil) ; where dragged ended (in screen coordinates!)
- (item-region (new-region)) ; a region that defines what we are dragging
- (window (view-container item)) ; the window in which the drag started
- (destination-window nil) ; the window in which the drag ended
- (drag-offset nil)) ; what's the offset after the drag?
- (unwind-protect ; we want to make sure that the item-region is disposed after an error
- (progn
- ;; Define the region that we want to drag:
- (open-region window)
- (with-port (wptr item)
- (#_FrameRect :ptr (slot-value item 'rectangle))) ;; The rectangle is OK, could ask the item.
- (close-region window item-region)
- ;; Do the drag and get the offset of the drag:
- (setq drag-offset
- (drag-inverted-region (view-container item) item-region :start current-mouse-loc))
- ;; Find out in which window the item landed:
- (setq end-position (add-points start-position drag-offset)
- destination-window
- (find-draw-dialog-in-point (add-points end-position (view-position window))))
- (when destination-window ; Do nothing if it lands nowhere
- (if (eq window destination-window)
- ;; Move within this window: set the item's position at the end of the drag:
- (unless (eq (type-of window) 'PALETTE) ; We don't want anyone to move palette items!
- (set-view-position item end-position))
- ; Move to another window: drop it there
- (move-item-to-window item end-position window destination-window))
- (view-draw-contents item)))
- (dispose-region item-region))))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; show-info
- ;;;
- ;;; This gets called whenever a draw item must show its information
- ;;;
- (defmethod show-info ((item draw-item))
- ;; Displays an information box for a draw-item
- )
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; bring-to-front
- ;;;
- ;;; Called whenever we want to bring a draw-item to the
- ;;; front of other draw-items in the draw-dialog window.
- ;;; This method simply passes the buck to the window
- ;;; (its container view).
- ;;;
- (defmethod bring-to-front ((item draw-item))
- (bring-item-to-front (view-container item) item))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; resize?
- ;;;
- ;;; Called to ask whether the user intends to resize the item
- ;;; The resize area is assumed to be a frame around but within
- ;;; the object's rectangle, offset by amount of slop.
- ;;;
- (defmethod resize? ((item draw-item) current-mouse-loc)
- (when (neq (type-of (view-container item)) 'PALETTE) ; PALETTE items can't be resized
- (rlet ((handles-rect :rect
- :topleft (view-position item)
- :bottomright (add-points (view-position item)
- (view-size item))))
- (inset-rect handles-rect *slop-in-pixels* *slop-in-pixels*)
- (not (point-in-rect-p handles-rect current-mouse-loc)))))
-
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; resize
- ;;;
- ;;; Called when item must be resized by user in some way
- ;;;
- (defmethod resize ((item draw-item) current-mouse-loc)
- (let* ((resize-direction (get-resize-direction item current-mouse-loc))
- (topleft (view-position item))
- (size (view-size item))
- (bottomright (add-points topleft size))
- (top (point-v topleft))
- (left (point-h topleft))
- (bottom (point-v bottomright))
- (right (point-h bottomright))
- new-mouse-loc new-mouse-h new-mouse-v
- ;; Two regions to produce inverted effect:
- (old-resize-region (new-region))
- (new-resize-region (new-region))
- ;; The rectangle enclosing the window
- (window-rectangle (rref (wptr item) :windowRecord.portrect))
- ;; The rectangle enclosing the draw-item:
- (item-rectangle (slot-value item 'rectangle))
- (window (view-container item)))
- ;(format t "Resizing ~a ~a..." resize-direction item)
- (#_InvertRect :ptr item-rectangle)
- (unwind-protect
- (loop ; until the mouse is released
- (if (not (mouse-down-p))
- (return nil)) ; We're through!
- ;; Update the location of the mouse in window coordinates
- (setq new-mouse-loc (view-mouse-position window)
- new-mouse-h (point-h new-mouse-loc)
- new-mouse-v (point-v new-mouse-loc))
- ;; Do resize graphics if mouse is within the window:
- (when (point-in-rect-p window-rectangle new-mouse-loc)
- (#_RectRgn :ptr old-resize-region
- :ptr item-rectangle) ; MIGHT BE NEW-RESIZE-REGION
- (case resize-direction
- (:top (and (< new-mouse-v bottom)
- (rset item-rectangle :rect.top new-mouse-v)))
- (:bottom (and (> new-mouse-v top)
- (rset item-rectangle :rect.bottom new-mouse-v)))
- (:left (and (< new-mouse-h right)
- (rset item-rectangle :rect.left new-mouse-h)))
- (:right (and (> new-mouse-h left)
- (rset item-rectangle :rect.right new-mouse-h)))
- (:topleft (and (< new-mouse-v bottom)
- (< new-mouse-h right)
- (rset item-rectangle :rect.topleft new-mouse-loc)))
- (:topright (when (and (< new-mouse-v bottom)
- (> new-mouse-h left))
- (rset item-rectangle :rect.right new-mouse-h)
- (rset item-rectangle :rect.top new-mouse-v)))
- (:bottomleft (when (and (> new-mouse-v top)
- (< new-mouse-h right))
- (rset item-rectangle :rect.left new-mouse-h)
- (rset item-rectangle :rect.bottom new-mouse-v)))
- (:bottomright (and (> new-mouse-v top)
- (> new-mouse-h left)
- (rset item-rectangle :rect.bottomright new-mouse-loc))))
- (#_RectRgn :ptr new-resize-region :ptr item-rectangle)
- (#_XOrRgn :ptr new-resize-region :ptr old-resize-region
- :ptr old-resize-region)
- (#_InvertRgn :ptr old-resize-region)
- ))
- (#_InvertRect :ptr item-rectangle)
- (set-view-size item (subtract-points (rref item-rectangle :rect.bottomright)
- (rref item-rectangle :rect.topleft)))
- (set-view-position item (rref item-rectangle :rect.topleft))
- (dispose-region old-resize-region)
- (dispose-region new-resize-region))))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; get-resize-direction
- ;;;
- ;;; Called when someone wants to find out in which direction
- ;;; the user intends to resize the item. Returns one of
- ;;; these:
- ;;; :topleft -- means resize topleft corner,
- ;;; :bottomleft -- means resize bottomleft corner
- ;;; :topright -- means resize topright corner
- ;;; :bottomright -- means resize bottomright corner
- ;;; :top -- means resize top side
- ;;; :bottom -- means resize bottom side
- ;;; :right -- means resize right side
- ;;; :left -- means resize left side
- ;;;
- (defmethod get-resize-direction ((item draw-item) current-mouse-loc)
- (let* ((item-topleft (view-position item))
- (item-bottomright (add-points item-topleft
- (view-size item)))
- (top (+ (point-v item-topleft) *slop-in-pixels*))
- (left (+ (point-h item-topleft) *slop-in-pixels*))
- (bottom (- (point-v item-bottomright) *slop-in-pixels*))
- (right (- (point-h item-bottomright) *slop-in-pixels*))
- (mouse-h (point-h current-mouse-loc))
- (mouse-v (point-v current-mouse-loc)))
- (cond ((<= mouse-h left)
- (if (<= mouse-v top)
- :topleft
- (if (>= mouse-v bottom)
- :bottomleft
- :left)))
- ((>= mouse-h right)
- (if (<= mouse-v top)
- :topright
- (if (>= mouse-v bottom)
- :bottomright
- :right)))
- ((<= mouse-v top)
- :top)
- (T
- :bottom))))
-
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; DRAW-ITEM SUBCLASSES
- ;;;
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; round-button
- ;;;
- (defclass round-button (draw-item button-dialog-item)
- ()
- )
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; check-box
- ;;;
- (defclass check-box (draw-item check-box-dialog-item)
- ()
- )
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; radio-button
- ;;;
- (defclass radio-button (draw-item radio-button-dialog-item)
- ()
- )
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; text
- ;;;
- (defclass text (draw-item fred-dialog-item)
- ()
- )
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; rectangle
- ;;;
- (defclass rectangle (draw-item)
- ()
- )
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; view-draw-contents
- ;;;
- ;;; Teach rectangle how to draw itself
- ;;;
- (defmethod view-draw-contents ((rectangle rectangle))
- (with-port (wptr rectangle)
- (#_FrameRect :ptr (slot-value rectangle 'rectangle)))
- (call-next-method))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; oval
- ;;;
- (defclass oval (draw-item)
- ()
- )
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; view-draw-contents
- ;;;
- ;;; Teach oval how to draw itself
- ;;;
- (defmethod view-draw-contents ((oval oval))
- (with-port (wptr oval)
- (#_FrameOval :ptr (slot-value oval 'rectangle)))
- (call-next-method))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; icon-draw-item
- ;;;
- (defclass icon-draw-item (draw-item resource)
- ()
- (:default-initargs :view-size #@(32 32)))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; view-draw-contents
- ;;;
- ;;; This draws a icon-draw-item (as a "cicn") into the appropiate rectangle.
- ;;; On B&W systems, an ICON (identical to the cicn when viewed in B&W)
- ;;; will be drawn.
- ;;;
- (defmethod view-draw-contents ((icon icon-draw-item))
- (let* ((resource-file "ccl:mini-app;resources")
- (handle (or (slot-value icon 'resource-handle)
- (get-resource-handle (slot-value icon 'resource-type)
- (slot-value icon 'resource-id)
- resource-file)))
- (rectangle (slot-value icon 'rectangle)))
- (when (handlep handle)
- (#_LoadResource :ptr handle) ;Must ensure that resource is in memory
- (with-port (wptr icon)
- (if *color-available*
- (#_PlotCIcon rectangle handle)
- (#_PlotIcon rectangle handle))))
- (call-next-method)))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; create-draw-item
- ;;;
- ;;; Creates and returns a DRAW-ITEM of the given class
- ;;;
- (defun create-draw-item (&key (name "Untitled")
- (class 'rectangle)
- (tool nil)
- (resource-type
- (if *color-available* "cicn" "ICON"))
- (resource-id nil))
- (let ((new-item (make-instance class :name name :tool tool)))
- (when (slot-exists-p new-item 'resource-handle)
- ;; We need resource information to make this object do its thing
- (unless resource-id
- (error "Object ~a needed a resource id to work" new-item))
- (setf (slot-value new-item 'resource-handle) nil)
- ;;Don't get the handle yet; make save-application easier
- (setf (slot-value new-item 'resource-id) resource-id)
- (setf (slot-value new-item 'resource-type) resource-type))
- new-item))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; create-tool
- ;;;
- ;;; Creates and returns a tool of the given class
- ;;;
- (defun create-tool (&rest init-args)
- (apply #'create-draw-item (nconc init-args (list :tool T))))
-
-
- ;end of file draw-item-class.lisp
- ;------------------------------------------------
-